/**
 * Created by hms on 2020-08-22.
 */
import LogAPI from '../api/log.js'

export const Log={
    state:{
        loglist:[],
        log_total_count:0,
        editLogStatus:-1,     //插入状态 0失败  1成功  -1不改变
        loginfo:[],
        delLogStatus:-1       //删除状态
    },
    mutations:{
        setLogList(state,data){
            state.loglist=data;
        },
        setTotalCount(state,count){
            state.log_total_count=count;
        },
        setEditLogStatus(state,status){
            state.editLogStatus=status;
        },
        setLogInfo(state,info){
            state.loginfo=info;
        },
        setDelLogStatus(state,status){
            state.delLogStatus=status;
        }
    },
    actions:{
        loadLogList(context,data){
            LogAPI.getLogList(data).then(function(response){
                if(response.data.code==1){
                    context.commit('setLogList',response.data.data.list);
                    context.commit('setTotalCount',response.data.data.total_count);
                }
            })
        },
        editLog(context,data){
            LogAPI.editLog(data).then(function(response){
                context.commit('setEditLogStatus',response.data.code);
            })
        },
        //获取详情
        loadLogInfo(context,data){
            LogAPI.getLogInfo(data).then(function(response){
                if(response.data.code==1){
                    context.commit('setLogInfo',response.data.info);
                }
            })
        },
        //删除
        delLog(context,data){
            LogAPI.delLog(data).then(function(response){
                context.commit('setDelLogStatus',response.data.code);
            })
        }
    },
    getters:{
        getLogList:state => {
            return state.loglist;
        },
        getLogTotalCount:state => {
            return state.log_total_count;
        },
        getEditLogStatus:state=>{
            return state.editLogStatus;
        },
        getLogInfo:state => {
            return state.loginfo;
        },
        getDelLogStatus:state => {
            return state.delLogStatus;
        }
    }
}
